//
//  GivemePassViewController.m
//  OneWordNew
//
//  Created by qianfeng001 on 15-7-7.
//  Copyright (c) 2015年 朱共营. All rights reserved.
//

#import "GivemePassViewController.h"
#import "AFNetworking.h"
@interface GivemePassViewController ()
{
    AFHTTPRequestOperationManager *_manager;

}
@end

@implementation GivemePassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _manager=[AFHTTPRequestOperationManager manager];
    _manager.responseSerializer=[AFHTTPResponseSerializer serializer];
}
- (void)showAlietViewWithTitle:(NSString *)title message:(NSString *)message{
    UIAlertView *aler=[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [aler show];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


- (IBAction)sendClick:(UIButton *)sender {
    if (self.emailText.text==nil) {
        [self showAlietViewWithTitle:@"警告" message:@"邮箱不能为空"];
    }
    NSString *username=[self.emailText.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dict=@{@"username":username,
                         @"key":@"3a4b2a12539a916c040d069ae8ac8310"};
    NSString *url=[kgetpwdUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [_manager POST:url parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            if ([dict[@"code"] isEqual:@(0)]) {
                [self showAlietViewWithTitle:@"提示" message:dict[@"msg"]];
                
            }else{
            
                [self showAlietViewWithTitle:@"警告" message:dict[@"msg"]];
            }
            
            
            
        }
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
}
@end
